#!/bin/bash

# 定义变量方便修改
table_db=cy_database 
hive=/home/software/hive-2.3.6/bin/hive

# 如果是输入的日期按照取输入日期；如果没输入日期取当前时间的前一天
if [ -n "$1" ] ;then
	do_date=$1
else 
	do_date=`date -d "-1 day" +%F`  
fi 

sql="
with
tmp_enterprise as
(	select 
		id,
		user_id,
		ent_name,
		short_name,
		social_security_number,
		industry_code,
		business_code,
		business_nature_code,
		industry_type,
		business_type,
		business_nature,
		uniform_social_credit_code,
		scale,
		scale_code,
		financing_stage,
		registered_capital,
		registration_authority,
		establishment,
		introduction,
		logo,
		corporate_welfare,
		business_license,
		organization_code_certificate,
		id_card_front,
		id_card_back,
		province_code,
		city_code,
		area_code,
		street_code,
		province,
		city,
		area,
		street,
		address,
		latitude,
		longitude,
		status,
		views,
		contact_person,
		phone,
		manager_name,
		manager_phone,
		manager_id_card_num,
		manager_qq,
		manager_email,
		manager_position,
		created_time,
		updated_time,
		examine_status,
		register_address,
		sys_area_code,
		batchNumber,
		register_province_code,
		register_city_code,
		register_area_code,
		register_province,
		register_city,
		register_area,
		ent_level,
		is_important
  from cy_database.dwd_enterprise ee
  where ee.dt='2020-06-17' and ee.id is not null
)

insert overwrite table cy_database.dws_enterprise_info partition(dt='2020-06-17')
	select
		id,
		user_id,
		ent_name,
		short_name,
		social_security_number,
		industry_code,
		business_code,
		business_nature_code,
		industry_type,
		business_type,
		business_nature,
		uniform_social_credit_code,
		scale,
		scale_code,
		financing_stage,
		registered_capital,
		registration_authority,
		establishment,
		introduction,
		logo,
		corporate_welfare,
		business_license,
		organization_code_certificate,
		id_card_front,
		id_card_back,
		province_code,
		city_code,
		area_code,
		street_code,
		province,
		city,
		area,
		street,
		address,
		latitude,
		longitude,
		status,
		views,
		contact_person,
		phone,
		manager_name,
		manager_phone,
		manager_id_card_num,
		manager_qq,
		manager_email,
		manager_position,
		created_time,
		updated_time,
		examine_status,
		register_address,
		sys_area_code,
		batchNumber,
		register_province_code,
		register_city_code,
		register_area_code,
		register_province,
		register_city,
		register_area,
		ent_level,
		is_important
	from tmp_enterprise
;



"
$hive -e "$sql"